/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package easy.core.bean;


import easy.core.util.ValidaEmail;
import easy.entities.Email;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author DanielPinheiro
 */

public class EmailManagedBean extends BaseBean {
    private static final long serialVersionUID = 2757386691613481154L;

    private Email emailInformado    = new Email();
    private List<Email> listaEmail  = new ArrayList<Email>();
    
    private boolean renderedListaEmailCliente;

    public EmailManagedBean() {
    }

    public void adicionar(){
        String email = getEmailInformado().getEmail();
        if(ValidaEmail.testaEmail(email)){
            if(!listaEmail.contains(emailInformado)){
                listaEmail.add(emailInformado);
            }
        }else{
            addErrorMessage("Email");
        }

    }

    public void excluir(){
        getListaEmail().remove(emailInformado);
        emailInformado = new Email();
    }

    //Qualquer edição
    public void editar(){
    }

    /**
     * @return the emailInformado
     */
    public Email getEmailInformado() {
        return emailInformado;
    }

    /**
     * @param emailInformado the emailInformado to set
     */
    public void setEmailInformado(Email emailInformado) {
        this.emailInformado = emailInformado;
    }

    /**
     * @return the listaEmail
     */
    public List<Email> getListaEmail() {
        return listaEmail;
    }

    /**
     * @param listaEmail the listaEmail to set
     */
    public void setListaEmail(List<Email> listaEmail) {
        this.listaEmail = listaEmail;
    }

    /**
     * @return the renderedListaEmailCliente
     */
    public boolean isRenderedListaEmailCliente() {
        renderedListaEmailCliente = false;
        if(listaEmail != null && listaEmail.size() > 0){
            renderedListaEmailCliente = true;
        }
        return renderedListaEmailCliente;
    }

    /**
     * @param renderedListaEmailCliente the renderedListaEmailCliente to set
     */
    public void setRenderedListaEmailCliente(boolean renderedListaEmailCliente) {
        this.renderedListaEmailCliente = renderedListaEmailCliente;
    }

}
